/*
 * UART.c
 *
 *  Created on: Aug 10, 2012
 *      Author: Vu Minh Hoang
 */
#include "UART.h"

void UART_init(void)
{
	PxSEL_RXD |= RXD_BIT;
	PxSEL_TXD |= TXD_BIT;
	PxSEL2_RXD |= RXD_BIT;
	PxSEL2_TXD |= TXD_BIT;
	UART_Disable();
	UCAxCTL1 |= UCSSEL_2;
	  UCAxBR0 = 0x8b;                            // 16MHz 115200
	  UCAxBR1 = 0x00;                              // 16MHz 115200
	  UCAxMCTL = UCBRS0;                        // Modulation UCBRSx = 1
	  UART_Enable();
}

void UART_Enable(void)
{
	UCAxCTL1 &= ~UCSWRST;
}
void UART_Disable(void)
{
	UCAxCTL1 |= UCSWRST;
}

// Transmit a character from the SCI
void UART_SendAChar(unsigned char a)
{
	while (!(UCAxIFG&UCAxTXIFG));
	UCAxTXBUF = a;
}

void UART_SendAMsg(char * msg)
{
    unsigned int i;
    i = 0;
    while(msg[i] != '\0')
    {
        UART_SendAChar(msg[i]);
        i++;
    }
}

/**
* @brief <b>Function Name</b>:     : UART_Interrupt_Enable
* @brief  <b>Description</b>: Enables Individual UART interrupts
* @param Input Parameters:
* <BR> uint8_t <b>interruptFlags</b> is the logical OR of any of the
* following:
*  <BR> UCBxRXIE		:Receive interrupt
*  <BR> UCBxTXIE       :Transmit interrupt
* @return Return Values: None
**/
void UART_Interrupt_Enable(uint8_t interruptFlags)
{
	UCAxIE |= interruptFlags;
}

/**
* @brief <b>Function Name</b>:     : UART_Interrupt_Disable
* @brief  <b>Description</b>: Disables Individual UART interrupts
* @param Input Parameters:
* <BR> uint8_t <b>interruptFlags</b> is the logical OR of any of the
* following:
*  <BR> UCBxRXIE		:Receive interrupt
*  <BR> UCBxTXIE       :Transmit interrupt
* @return Return Values: None
**/
void UART_Interrupt_Disable(uint8_t interruptFlags)
{
	UCAxIE &= ~interruptFlags;
}

/**
* @brief <b>Function Name</b>:     : UART_Interrupt_Clear
* @brief  <b>Description</b>: Clears Individual UART interrupts flags
* @param Input Parameters:
* <BR> uint8_t <b>interruptFlags</b> is the logical OR of any of the
* following:
*  <BR> UCBxRXIFG		:Receive interrupt
*  <BR> UCBxTXIFG       :Transmit interrupt
* @return Return Values: None
**/
void UART_Interrupt_Clear(uint8_t interruptFlags)
{
	UCAxIFG &= ~interruptFlags;
}

#pragma vector=USCI_Ax_RX_VECTOR
__interrupt void USCIAx_RX_ISR(void)
{

}

